package xyz.xtt.asset.controller;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.nacos.shaded.com.google.common.primitives.Longs;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.asset.client.response.TransactionResponse;
import xyz.xtt.asset.entity.TblAssetTransaction;
import xyz.xtt.asset.service.ITblAssetTransactionService;
import xyz.xtt.asset.vo.HotTopAssetVo;
import xyz.xtt.common.objects.DozerUtil;
import xyz.xtt.common.response.ApiResult;

/**
 * @author huqibo
 * @date 2025/03/24
 */
@Tag(name = "交易管理", description = "交易管理")
@Slf4j
@RequestMapping("/api/nft/asset")
@RestController
public class TransactionController {

	@Autowired
	private ITblAssetTransactionService iTblAssetTransactionService;

	/**
	 * 某有资产的详情 检查余额
	 * 
	 * @param assetId
	 * @return
	 */
	@GetMapping("/queryNotPaiedPersonalMintUpChaninOrder")
	public ApiResult<TransactionResponse> queryNotPaiedPersonalMintUpChaninOrder(@RequestParam("assetId") Long assetId, @RequestParam("appUid") String appUid) {
		log.info("/api/nft/asset/accountInfoCheckAmount assetId:{},appUid:{}", assetId, appUid);
		TblAssetTransaction accountNoCheckAmount = iTblAssetTransactionService.queryNotPaiedPersonalMintUpChaninOrder(assetId, appUid);
		TransactionResponse transfor = DozerUtil.transfor(accountNoCheckAmount, TransactionResponse.class);
		return ApiResult.ok(transfor);
	}

	@GetMapping("/queryNotPayOrder")
	public ApiResult<TransactionResponse> queryNotPayOrder(@RequestParam("assetId") Long assetId, @RequestParam("appUid") String appUid) {
		log.info("/api/nft/asset/accountInfoCheckAmount assetId:{},appUid:{}", assetId, appUid);
		TblAssetTransaction accountNoCheckAmount = iTblAssetTransactionService.queryNotPayOrder(assetId, Longs.tryParse(appUid));
		TransactionResponse transfor = DozerUtil.transfor(accountNoCheckAmount, TransactionResponse.class);
		return ApiResult.ok(transfor);
	}

	/**
	 * 历史最大成交价
	 * 
	 * @param appUid
	 * @param goodsId
	 * @return
	 */
	@GetMapping("/buyMaxPriceWithHistory")
	public ApiResult<BigDecimal> buyMaxPriceWithHistory(@RequestParam("appUid") String appUid, @RequestParam("goodsId") String goodsId) {
		log.info("/api/nft/asset/buyMaxPriceWithHistory appUid:{},goodsId:{}", appUid, goodsId);
		BigDecimal buyMaxPriceWithHistory = iTblAssetTransactionService.buyMaxPriceWithHistory(appUid, goodsId);
		return ApiResult.ok(buyMaxPriceWithHistory);
	}

	@Operation(summary = "热卖榜")
	@GetMapping("/get_hot_top")
	public ApiResult<List<HotTopAssetVo>> getHotTopList() {
		return ApiResult.ok(iTblAssetTransactionService.getHotTopList());
	}

	/**
	 * @param orderId
	 * @return
	 */
	@Operation(summary = "交易详情")
	@GetMapping("/transactionInfo")
	public ApiResult<TransactionResponse> transactionInfo(Long orderId) {
		log.info("/api/nft/asset/transactionInfo orderId:{}", orderId);
		TblAssetTransaction accountNoCheckAmount = iTblAssetTransactionService.transactionInfo(orderId);
		TransactionResponse transfor = DozerUtil.transfor(accountNoCheckAmount, TransactionResponse.class);
		return ApiResult.ok(transfor);
	}

	@GetMapping("/queryPaySyncOne")
	public ApiResult<TransactionResponse> queryPaySyncOne(@RequestParam("buyUserId") String buyUserId, @RequestParam("orderId") Long orderId) {
		log.info("/api/nft/asset/queryPaySyncOne orderId:{},buyUserId:{}", orderId, buyUserId);
		TblAssetTransaction queryPaySyncOne = iTblAssetTransactionService.queryPaySyncOne(buyUserId, orderId);
		TransactionResponse transfor = DozerUtil.transfor(queryPaySyncOne, TransactionResponse.class);
		return ApiResult.ok(transfor);
	}
}
